# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=gtest
pkgver=1.14.0
pkgrel=1
pkgdesc="Google Test - C++ testing utility based on the xUnit framework (like JUnit)"
url="https://github.com/google/googletest"
arch="all"
license="BSD-3-Clause"
depends_dev="$pkgname=$pkgver-r$pkgrel gmock=$pkgver-r$pkgrel"
makedepends="$depends_dev cmake python3-dev samurai"
subpackages="$pkgname-dev gmock $pkgname-src"
source="$pkgname-$pkgver.tar.gz::https://github.com/google/googletest/archive/refs/tags/v$pkgver.tar.gz"
builddir="$srcdir/googletest-$pkgver"

build() {
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=ON \
		-DPYTHON_EXECUTABLE=python3 \
		-Dgtest_build_tests=ON \
		-DBUILD_GMOCK=ON
	cmake --build build
}

check() {
	# fails of x86
	ctest --test-dir build -E "(googletest-port-test|googletest-printers-test)"
}

package() {
	DESTDIR="$pkgdir" cmake --build build --target install
	find "$pkgdir" -name '*.pump' -print -delete
}

gmock() {
	pkgdesc="Google Mock - A library for writing and using C++ mock classes"
	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/libgmock*.so* "$subpkgdir"/usr/lib/
}

src() {
	arch="noarch"
	mkdir -p "$subpkgdir"/usr/src/$pkgname/src
	mv  "$builddir"/googletest/src/* "$subpkgdir"/usr/src/$pkgname/src
}

sha512sums="
765c326ccc1b87a01027385e69238266e356361cd4ee3e18e3c9d137a5d11fa5d657c164d02dd1be8fe693c8e10f2b580588dbfa57d27f070e2750f50d3e662c  gtest-1.14.0.tar.gz
"
